﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using UnityEditor;
using UnityEngine;

public class Replace  {
    public delegate bool TagertGameObj(GameObject go);
    public delegate void RefGameObj(GameObject go);
    
   // [MenuItem("Tools/Replace/ReplaceJumper")]
    public static void RefObj(TagertGameObj tagert,RefGameObj refobj)
    {
        string[] ids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/Prefabs" });
        for (int i = 0; i < ids.Length; i++)
        {
           string path = AssetDatabase.GUIDToAssetPath(ids[i]);
           GameObject obj = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
           Debug.Log(obj.name);
            if (tagert(obj))
            {
                refobj(obj);
            }
        }

        AssetDatabase.SaveAssets();
        Debug.Log("Done");
    }

    [MenuItem("Tools/Replace/AdapterToInitial")]
    public static void TransPosComponent()
    {
        GameObject[] go= Selection.gameObjects;
        foreach (var i in go)
        {
            Debug.Log(i.name);
            PosAdapter j = i.GetComponent<PosAdapter>();
              if (j!=null)
               {
                   GameObject.DestroyImmediate(j,true);
                   i.AddComponent<PosInitial>();
               }
           
        }
    }

    [MenuItem("Tools/Replace/AddPosInitial")]
    public static void MapAddPosInitial()
    {
        GameObject[] go = Selection.gameObjects;
        foreach (var i in go)
        {
            Debug.Log(i.name);
            PosInitial pi= i.AddComponent<PosInitial>();
           // pi.deviation = 0.64f;
        }
    }


    [MenuItem("Tools/Replace/Check")]
    public static void Check()
    {
        GameObject[] go = Selection.gameObjects;
        foreach (var i in go)
        {
            Debug.Log(i.name);
            if (i.GetComponents<PosInitial>().Length>1)
            {
                GameObject.DestroyImmediate(i.GetComponent<PosInitial>(), true);
            }
            // pi.deviation = 0.64f;
        }
    }

    [MenuItem("Tools/Check/CheckAnimationName")]
    public static void CheckName()
    {
        GameObject[] go = Selection.gameObjects;
        foreach (var i in go)
        {
            Debug.Log(i.name);
            if (i.name=="animation")
            {
                i.name = Helper.subAnimation;
            }
            if (i.GetComponent<PosInitial>()!=null)
            {
                i.GetComponent<PosInitial>().deviation = 1.28f;
            }
        }
    }

}
            //Jumper j = obj.GetComponent<Jumper>();
         /*   if (j!=null)
            {
                GameObject.DestroyImmediate(j,true);
                obj.AddComponent<PosAdapter>();
            }
        */
